// 0命甘雨 
// 武器推荐  阿莫斯 > 其他

// 冰套 乐团 各有优劣 都刷不冲突 反正水本也要刷 人物也要练
// 大招在打群怪(集中)会叠加超模 少数量怪或者单个精英效果一般
// 冰套注意不要丢失套装暴击效果 一旦丢失 暴击率大幅度下降 双爆比例失调 期望伤害大幅度降低(不能打融化 期望伤害降低严重)

// 圣遗物主词条选择 攻击 冰伤 爆伤
// 冰套副词 双爆 > 攻击百分比 > 固定攻击
// 乐团副词 双爆 > 攻击百分比 > 精通 > 固定攻击

// 冰套极限面板
// 攻击力 2803 暴击40.1  爆伤298.8  强化 攻击百分比34.8(6) 暴击15.6(4) 爆伤117(15)
// 期望伤害
// 蓄力两段 89362
// 仅第二段 56318
// q 9794

// 乐团极限面板
// 攻击力 2508 暴击79.1  爆伤252  精通195(乐团+初始四词条里的)  强化 攻击百分比11.6(2) 暴击54.6(14) 爆伤70.2(9)
// 期望伤害
// 蓄力两段 75037     融化 151009 
// 仅第二段 47290      融化 95170
// q 7092   融化 14273













let charaters = {
    gy : {
        name: "lv90甘雨", 
        base: 335,
        criticalRate: 5 + 20,
        criticalStrike: 50 + 38.4
    }
}

let weapons = {
    tiankj: {
        name:"lv90天空弓",  // 每两秒 一次 1.25 * 攻击力 物理伤害
        base: 674,
        criticalRate: 22.1,
        criticalStrike:40
    },
    amosi: {
        name: "lv90阿莫斯",  // 普攻蓄力24增伤   远程蓄力发射过0.5s 80增伤
        base: 608,
        attRate:49.6
    },
    juexian: {
        name: "lv90绝弦",  // 技能大招 48 增伤
        base: 510,
        "精通":165
    }
}
let normal_clips = calc_clips_normal();
let normal_clips2 = calc_clips_normal(2);
let charactersDmg = []

// 蓄力射击  2.3   3.92
// e  2.38
// q  1.26*n
// 蓄力射击暴击率+20
// q范围内20冰伤
// 蓄力射击降低冰抗15
// q范围敌人受到伤害增加 5% 10% 15% 20% 25% 12s
// e后秒放蓄力射击

// 甘雨阿莫斯     
charactersDmg.push(getDMG([charaters.gy,weapons.amosi,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 乐团 80 精通  35射击增伤
    data.精通 += 80
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0 }
    
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    // 蓄力射击
    let a = getDmgDps({...data,dmgRate:data.dmgRate + 104 + 35}, 2.3+3.92) * q(10) * df(90,90); 
    let aRea = getDmgDps({...data,dmgRate:data.dmgRate + 1044 + 35}, 2.3+3.92, rea) * q(10) * df(90,90); 

    data.criticalRate -= 20;
    let edmg = getDmgDps(data, 2.38) * q(10) * df(90,90); // e
    let qd = getDmgDps(data, 1.26) * q(10) * df(90,90); // q
    let qdRea = getDmgDps(data, 1.26, rea) * q(10) * df(90,90); // q
    
    let ret = a * 3 + aRea * 3 + edmg*2 + qd*10 + qdRea * 5
    return {point:ret, data, second, attack ,a,aRea,edmg,qd,qdRea,msg:"0命满精 乐团"}
}))
// // 甘雨阿莫斯
// charactersDmg.push(getDMG([charaters.gy,weapons.amosi,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
//     // 冰套
//     data.dmgRate += 15 // 冰套15冰伤
//     data.criticalRate += 40  // 冰套当常驻暴击
//     let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0 }
    
//     let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
//     // 蓄力射击
//     let a = getDmgDps({...data,dmgRate:data.dmgRate + 52}, 2.3+3.92) * q(-5) * df(90,90); 
    
//     data.criticalRate -= 20;
//     let edmg = getDmgDps(data, 2.38) * q(-5) * df(90,90); // e
//     let qd = getDmgDps(data, 1.26) * q(-5) * df(90,90); // q
//     data.criticalRate -= 20;
//     let aRea = getDmgDps({...data,dmgRate:data.dmgRate + 52}, 2.3+3.92, rea) * q(-5) * df(90,90); 
//     let qdRea = getDmgDps(data, 1.26, rea) * q(-5) * df(90,90); // q
    
//     let ret = a * 6 + aRea * 0 + edmg*2 + qd*15 + qdRea * 0
//     return {point:ret, data, second, attack ,a,aRea,edmg,qd,qdRea,msg:"冰套0精阿莫斯"}
// }))
// 甘雨阿莫斯
charactersDmg.push(getDMG([charaters.gy,weapons.amosi,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 冰套
    data.dmgRate += 15 // 冰套15冰伤
    data.dmgRate += 20
    data.criticalRate += 40 + 15  // 冰套当常驻暴击
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0 }
    
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    // 蓄力射击
    let a = getDmgDps({...data,dmgRate:data.dmgRate + 104}, 2.3+3.92) * q(-35) * df(90,90); 
    let a2 = getDmgDps({...data,dmgRate:data.dmgRate + 104}, 3.92) * q(-35) * df(90,90); 
    
    data.criticalRate -= 20;
    let edmg = getDmgDps(data, 2.38) * q(-35) * df(90,90); // e
    let qd = getDmgDps(data, 1.26) * q(-35) * df(90,90); // q
    data.criticalRate -= 35;
    let aRea = getDmgDps({...data,dmgRate:data.dmgRate + 104}, 2.3+3.92, rea) * q(-35) * df(90,90); 
    data.criticalRate -= 20;
    let qdRea = getDmgDps(data, 1.26, rea) * q(-35) * df(90,90); // q
    
    let ret = a * 6 + aRea * 0 + edmg*2 + qd*10 + qdRea * 0
    return {point:ret, data, second, attack ,a,a2,aRea,edmg,qd,qdRea,msg:"冰套"}
}))

// // 甘雨阿莫斯  甘雨 温迪 莫娜(50增伤) 班尼特(800固定攻击 20%攻击)
// charactersDmg.push(getDMG([charaters.gy,weapons.amosi,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
//     // 乐团 80 精通  35射击增伤
//     data.attRate += 20 // 宗室
//     data.精通 += 80
//     data.dmgRate += 50   // 莫娜增伤
//     data.dmgRate += 20
//     let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0 }
    
//     let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
//     // 蓄力射击
//     let a = getDmgDps({...data,dmgRate:data.dmgRate + 139}, 2.3+3.92) * q(-5) * df(90,90); 
//     let aRea = getDmgDps({...data,dmgRate:data.dmgRate + 139}, 2.3+3.92, rea) * q(-5) * df(90,90); 
//     let a2Rea = getDmgDps({...data,dmgRate:data.dmgRate + 139}, 3.92, rea) * q(-5) * df(90,90); 
//     let a2 = getDmgDps({...data,dmgRate:data.dmgRate + 139}, 3.92) * q(-5) * df(90,90); 

//     data.criticalRate -= 20;
//     let edmg = getDmgDps(data, 2.38) * q(-5) * df(90,90); // e
//     let qd = getDmgDps(data, 1.26) * q(-5) * df(90,90); // q
//     let qdRea = getDmgDps(data, 1.26, rea) * q(-5) * df(90,90); // q
    
//     let ret = a*3 + aRea * 3 + a2Rea * 0 + edmg*2 + qd*8 + qdRea * 2
//     return {point:ret, data, second, attack ,a,aRea,a2Rea,a2,edmg,qd,qdRea,msg:"乐团"}
// }))


console.log(charactersDmg.sort((a,b)=>b.point-a.point));


function getDMG(dataarr, getRet){
    let chance = 25;
    let _ret = [];
    for (let index = 0; index <= chance; index++) {
        let criticalStrike = index; 
        for (let index2 = 0; index2 <= chance - index; index2++) {
            let criticalRate = index2;
            for (let index3 = 0; index3 <= chance-index-index2; index3++) {
                let attRate = index3;
                let defenceRate = chance - index - index2 - index3;
                _ret.push({
                    精通: 23 * defenceRate,
                    attRate:5.8 * attRate,
                    criticalRate:3.9 * criticalRate,
                    criticalStrike:7.8 * criticalStrike
                });
            }
        }
    }
    _ret = _ret.map(second => {
        let panel = getPanel([...dataarr, second]);
        return  getRet(panel, second)
    })
    _ret.sort((b,a)=> a.point-b.point)
    return _ret[0]
}

function getDmgDps(data, rate=1, rea){
    let criticalRate = data.criticalRate
    if(criticalRate > 100){criticalRate = 100}
    let baseat = data.base * (1 + data.attRate/100) + data.fixedAtt;
    let bdmg = baseat * (1 + data.criticalStrike/100);
    let bdps = (criticalRate * 10 * bdmg + (1000-criticalRate * 10)*baseat)/1000
    let adddmg = bdps * (1 + data.dmgRate/100)
    if(rea){
        let {精通, 系数, 精通增伤} = rea
        let tmp = 1 + 精通增伤 + jt(精通);
        return adddmg * rate * 系数 * tmp
    }
    return adddmg * rate
}

function getPanel(arr){
    let info = {name1:"",name2:""};
    arr.forEach((item, i)=>{
        if(item.name){
            info["name" + (i+1)] = item.name
        }
        for (const key in item) {
            if(key !== "name"){
                if(info[key]){
                    info[key] += item[key]
                } else {
                    info[key] = item[key]
                }
            }
        }
    })
    return info
}

function q (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

function df(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

// 固定攻击力 19  防御力23 生命值299 5.3% 
function calc_clips_normal (n) {
    let clips = [
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            fixedAtt:19,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate:n!=2? 0:3.9,
            criticalStrike:n!=2? 7.8:0
        }
    ]
    let data = {}
    clips.forEach(item => {
        for (const key in item) {
            data[key] = data[key]? (data[key]+item[key]) : item[key]
        }
    })
    return data
}

function jt(k){
    if(k == 0){return 0}
    return Math.log(0.99316499 + 0.00209988607 * k + 0.0000001213236971*k*k)
}